package com.base.api.controller.commodity;

import com.base.api.dto.commodity.*;
import com.base.api.service.commodity.CommodityApiService;
import com.base.api.vo.commodity.ExplosiveVO;
import com.base.api.vo.commodity.BountyListVO;
import com.base.api.vo.commodity.GoodsShareVO;
import com.base.api.vo.commodity.OrderCommodityDetailVO;
import com.base.log.WebLog;
import com.base.result.ResponseResult;
import com.base.self.entity.Commodity;
import com.base.self.entity.CommodityCallPlanDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Slf4j
@RequestMapping("/api/commodity")
@Api(tags = "商品信息")
public class CommodityApiController {

    private final CommodityApiService commodityApiService;

    public CommodityApiController(CommodityApiService commodityApiService) {
        this.commodityApiService = commodityApiService;
    }

    @ApiOperation(value="商品爆品查询")
    @PostMapping(value = "/explosiveList", produces = "application/json;charset=UTF-8")
    @Validated
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = ExplosiveVO.class),
    })
    @WebLog
    public ResponseResult explosiveList(final @Valid ExplosiveListDTO explosiveListDTO){
        return commodityApiService.explosiveList(explosiveListDTO);
    }

    @ApiOperation(value="商品详情查询")
    @PostMapping(value = "/commodityDetail", produces = "application/json;charset=UTF-8")
    @Validated
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = Commodity.class),
    })
    @WebLog
    public ResponseResult commodityDetail(final @Valid CommodityDetailDTO commodityDetailDTO){
        return commodityApiService.commodityDetail(commodityDetailDTO);
    }

    @ApiOperation(value="订单确认商品信息")
    @PostMapping(value = "/orderCommodityDetail", produces = "application/json;charset=UTF-8")
    @Validated
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = OrderCommodityDetailVO.class),
    })
    @WebLog
    public ResponseResult orderCommodityDetail(final @Valid OrderCommodityDetailDTO orderCommodityDetailDTO){
        return commodityApiService.orderCommodityDetail(orderCommodityDetailDTO);
    }

    @ApiOperation(value="商品详情链接")
    @GetMapping(value = "/commodityDetailLink", produces = "application/json;charset=UTF-8")
    @Validated
    public ModelAndView commodityDetailLink(HttpServletRequest request, final @Valid CommodityDetailLinkDTO commodityDetailLinkDTO){
        return new ModelAndView(commodityApiService.commodityDetailLink(request, commodityDetailLinkDTO));
    }

    @ApiOperation(value="首页积分抵扣查询")
    @PostMapping(value = "/commodityBountyList", produces = "application/json;charset=UTF-8")
    @Validated
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = BountyListVO.class),
    })
    @WebLog
    public ResponseResult commodityBountyList(final @Valid CommodityBountyListDTO commodityBountyListDTO){
        return commodityApiService.commodityBountyList(commodityBountyListDTO);
    }

    @ApiOperation(value="积分兑换商品筛选")
    @PostMapping(value = "/commodityBountyScreen", produces = "application/json;charset=UTF-8")
    @Validated
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = BountyListVO.class),
    })
    @WebLog
    public ResponseResult commodityBountyScreen(final @Valid CommodityBountyScreenDTO commodityBountyScreenDTO){
        return commodityApiService.commodityBountyScreen(commodityBountyScreenDTO);
    }

    @ApiOperation(value="商品搜索")
    @PostMapping(value = "/commodityBountySearch", produces = "application/json;charset=UTF-8")
    @Validated
    @WebLog
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = BountyListVO.class),
    })
    public ResponseResult commodityBountySearch(final @Valid CommoditySearchDTO commoditySearchDTO){
        return commodityApiService.commodityBountySearch(commoditySearchDTO);
    }

    @ApiOperation(value="分类商品筛选")
    @PostMapping(value = "/classifyBountyScreen", produces = "application/json;charset=UTF-8")
    @Validated
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = BountyListVO.class),
    })
    @WebLog
    public ResponseResult classifyBountyScreen(final @Valid ClassifyBountyScreenDTO classifyBountyScreenDTO){
        return commodityApiService.classifyBountyScreen(classifyBountyScreenDTO);
    }

    @ApiOperation(value="商品分享信息")
    @PostMapping(value = "/goodsShare", produces = "application/json;charset=UTF-8")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = GoodsShareVO.class),
    })
    @WebLog
    public ResponseResult goodsShare(final @Validated GoodsShareDTO goodsShareDTO){
        return commodityApiService.goodsShare(goodsShareDTO);
    }

    @ApiOperation(value="礼包详情")
    @PostMapping(value = "/commodityCallPlanDetail", produces = "application/json;charset=UTF-8")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = CommodityCallPlanDetail.class),
    })
    @WebLog
    public ResponseResult commodityCallPlanDetail(final @Validated CommodityCallPlanDetailDTO commodityCallPlanDetailDTO){
        return commodityApiService.commodityCallPlanDetail(commodityCallPlanDetailDTO);
    }
}
